package com.groupsix.service.impl;

import com.groupsix.entity.Visitor;
import com.groupsix.mapper.VisitorMapper;
import com.groupsix.utils.PageInfo;
import com.groupsix.service.VisitorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 董盛昌
 * @Title: ${file_name}
 * @Package ${package_name}
 * @Description: 参观者业务逻辑接口实现类
 * @date 2021/10/16 15:32
 */
@Service
public class VisitorServiceImpl implements VisitorService {

    // 注入studentDao
    @Autowired
    private VisitorMapper visitorMapper;

    @Override
    public PageInfo findPageInfo(String vName, Integer vPhone, Integer pageIndex, Integer pageSize) {
        PageInfo pi = new PageInfo();
        pi.setPageIndex(pageIndex);
        pi.setPageSize(pageSize);
        //获取总条数
        Integer totalCount = visitorMapper.totalCount(vName,vPhone);
        if (totalCount>0){
            pi.setTotalCount(totalCount);
            //每一页显示学生信息数
            //currentPage = (pageIndex-1)*pageSize  当前页码数减1*最大条数=开始行数
            List<Visitor> visitorList =	visitorMapper.getVisitorList(vName,vPhone,
                    (pi.getPageIndex()-1)*pi.getPageSize(),pi.getPageSize());
            pi.setList(visitorList);
        }
        return pi;
    }

    @Override
    public int addVisitor(Visitor visitor) {
        return visitorMapper.addVisitor(visitor);
    }

    @Override
    public List<Visitor> getAll() {
        List<Visitor> visitorList = visitorMapper.getAll();
        return visitorList;
    }
}
